package com.imddy.spbatch001.service;

import com.imddy.spbatch001.entity.BlogInfo;
import com.imddy.spbatch001.repository.BlogInfoRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

@Service
public class BlogInfoService {
    private static final Logger log = LoggerFactory.getLogger(BlogInfoService.class);

    @Autowired
    private BlogInfoRepository blogInfoRepository;

    public BlogInfo getById(Integer id) {
        return blogInfoRepository.findById(id).get();
    }

    public List<BlogInfo> getByIds(Collection<Integer> ids) {
        return blogInfoRepository.findAllById(ids);
    }

    public BlogInfo saveOrUpdate(BlogInfo blogInfo) {
        return blogInfoRepository.saveAndFlush(blogInfo);
    }

    public List<BlogInfo> saveOrUpdate(Collection<BlogInfo> blogInfos) {
        return blogInfoRepository.saveAllAndFlush(blogInfos);
    }

    public void deleteById(Integer id) {
        blogInfoRepository.deleteById(id);
    }

    public void deleteByIds(Collection<Integer> ids) {
        blogInfoRepository.deleteAllById(ids);
    }

}
